package com.neborosoft.android.gui.adapters.viewpager;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.neborosoft.FlyingDog.android.MyActivity;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 11.11.12
 * Time: 15:32
 * To change this template use File | Settings | File Templates.
 */
public abstract class ElementsProvidingPagerAdapter<Element> extends PagerAdapter {
    private Context context;

    protected ElementsProvidingPagerAdapter(Context context) {
        this.context = context;
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    protected abstract Element getElement(int position);
    protected abstract int getRootLayoutId();

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Element element = getElement(position);

        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(getRootLayoutId(), null);
        container.addView(view);
        fillAudio(view, element);

        return view;
    }

    protected abstract void fillAudio(View view, Element element);

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }
}
